package com.wanmait.myhouse.managerController;

import com.wanmait.myhouse.dao.MediatorDAO;
import com.wanmait.myhouse.dao.MediatorFeedDAO;
import com.wanmait.myhouse.vo.FeedBack;
import com.wanmait.myhouse.vo.Mediator;
import com.wanmait.myhouse.vo.MediatorFeed;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("manager")
public class ManagerSystemsController {

    @PostMapping("replyMediator")
    public String replyMediator(MediatorFeed mediatorFeed){
        mediatorFeed.setDispose(true);
        MediatorFeedDAO mediatorFeedDAO = new MediatorFeedDAO();
        mediatorFeedDAO.updateById(mediatorFeed);
        return "redirect:/manager/mediatorFeedBack";
    }

    @GetMapping("systems")
    public String systems(MediatorFeed mediatorFeed , Model model){
        MediatorFeedDAO mediatorFeedDAO = new MediatorFeedDAO();
        FeedBack selectById = mediatorFeedDAO.selectById(mediatorFeed.getId());
        MediatorDAO mediatorDAO = new MediatorDAO();
        Mediator mediator = mediatorDAO.findById(mediatorFeed.getMediatorId());
        selectById.setMediator(mediator);
        model.addAttribute("feedBack",selectById);
        return "manager/systems";
    }
}
